﻿<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="#(ctx_path)/lib/html5shiv.js"></script>
<script type="text/javascript" src="#(ctx_path)/lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="#(ctx_path)/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="#(ctx_path)/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="#(ctx_path)/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="#(ctx_path)/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="#(ctx_path)/static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="#(ctx_path)/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>按钮权限配置</title>
</head>
<body>
<div class="page-container">

	<div class="mt-20">
		<input type="hidden" id="menuId" value="#(sysMenu.id)" />
		<input type="hidden" id="roleId" value="#(sysRole.id)" />
	<table id="layTab" class="table table-border table-bordered table-hover table-bg table-sort">
		<thead>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="" value=""></th>
				<th width="40">ID</th>
				<th width="120">名称</th>
				<th width="120">编码</th>
				<th width="80">按钮状态</th>
				<th width="">角色权限</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<tbody>

		</tbody>
	</table>
		<!--<div id="tabpage" class="text-r" style="padding-top:5px;"></div>-->
	</div>
</div>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="#(ctx_path)/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="#(ctx_path)/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="#(ctx_path)/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="#(ctx_path)/static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="#(ctx_path)/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<!--<script type="text/javascript" src="#(ctx_path)/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>-->
<script type="text/javascript" src="#(ctx_path)/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="#(ctx_path)/lib/laypage/1.2/LayPageTool.js"></script>
<script type="text/javascript">

	$(function(){
        initData();
    })

function initData(){
	//初始化第一页数据
    var parms = {"menuId":$("input#menuId").val(),"roleId":$("input#roleId").val()};
    $.ajax({
        type: 'POST',
        url: '#(ctx_path)/admin/roleAuth/findSysRoleMenuBtnByRoleIdAndMenuId',
        data: parms,
        dataType: 'json',
        success: function (data) {

			//拼凑html
			htmlStr(data,$(".table-sort tbody"));

        },
        error:function(data) {
            layer.msg('系统错误，请联系管理员！', {icon: 5,time:1500});
            console.log(data.msg);
        }
    });
}


function htmlStr(data,tbody){
    var html = "";
    $(tbody).html("");
    for (var i = 0; i < data.length; i++) {
        html += "<tr class=\"text-c\">";
        html += "<td><input type=\"checkbox\" value=\"1\" name=\"\"></td>";
        html += "<td>"+ data[i].id +"</td>";
        html += "<td>"+ data[i].name +"</td>";
        html += "<td>"+ data[i].code +"</td>";
        html += "<td>"+ getIshiddenHtmlByIshidden(data[i].ishidden) +"</td>";
        html += "<td class=\"text-c\">"+ getIsRoleID(data[i].roleid) +"</td>";
        html += "<td class=\"td-manage\">";
        html += getFnHtmlByStatus(data[i].id, data[i].roleid);
        html += "</td>";
        html += "</tr>";
    }
    $(tbody).html(html);
}

/*用户-停用*/
function role_stop(obj,buttonid,roleid){
	layer.confirm('是否取消授权吗？',function(index){
        var params = {"rmb.button_id":buttonid,"rmb.role_id":$("input#roleId").val(),"rmb.menu_id":$("#menuId").val(),"action":"del"};
		$.ajax({
			type: 'POST',
			url: '#(ctx_path)/admin/roleAuth/updateSysRoleMenuButton',
			data:params,
			dataType: 'json',
			success: function(data){
                if (data.isSuccess == true){
                    $(obj).parent().prev().html('<span class="label radius">未授权</span>');
                    $(obj).parent().prepend('<a style="text-decoration:none" onClick="role_start(this,' + buttonid + ','+roleid+')" href="javascript:;" title="授权"><i class="Hui-iconfont">&#xe615;</i></a>');
                    $(obj).remove();
                    layer.msg(data.result, {icon: 5,time:1000});
                }else{
                    layer.msg(data.result, {icon: 5,time:1500});
                }
			},
            error:function(data) {
                layer.msg('系统错误，请联系管理员！', {icon: 5,time:1500});
                console.log(data.msg);
            }
		});		
	});
}

/*-启用*/
function role_start(obj,buttonid,roleid){
	layer.confirm('是否授权吗？',function(index){
        var params = {"rmb.button_id":buttonid,"rmb.role_id":$("input#roleId").val(),"rmb.menu_id":$("#menuId").val(),"action":"add"};
		$.ajax({
			type: 'POST',
			url: '#(ctx_path)/admin/roleAuth/updateSysRoleMenuButton',
			data:params,
			dataType: 'json',
			success: function(data){
                if (data.isSuccess == true){
                    $(obj).parent().prev().html('<span class="label label-success radius">授权</span>');
                    $(obj).parent().prepend('<a style="text-decoration:none" onClick="role_stop(this,' + buttonid + ','+roleid+')" href="javascript:;" title="未授权"><i class="Hui-iconfont">&#xe631;</i></a>');
                    $(obj).remove();
                    layer.msg(data.result, {icon: 6,time:1000});
                }else{
                    layer.msg(data.result, {icon: 5,time:1500});
                }
			},
            error:function(data) {
                layer.msg('系统错误，请联系管理员！', {icon: 5,time:1500});
                console.log(data.msg);
            }
		});
	});
}

function getIshiddenHtmlByIshidden(isHidden) {
    var html = '';
    if (isHidden == 0 ) {
        html = '<span class="label label-success radius">启用</span>';
    }else {
        html = '<span class="label radius">停用</span>';
    }
    return html;
}
function getIsRoleID(roleid) {
	var html = '';
	if (roleid != null ) {
		html = '<span class="label label-success radius">授权</span>';
	}else {
		html = '<span class="label radius">未授权</span>';
	}
	return html;
}

function getFnHtmlByStatus(buttonid,roleid){
    var html = '';
    if (roleid != null ) {
        html = '<a style="text-decoration:none" onClick="role_stop(this,' + buttonid + ','+roleid+')" href="javascript:;" title="取消授权"><i class="Hui-iconfont">&#xe631;</i></a>';
    }else {
        html = '<a style="text-decoration:none" onClick="role_start(this,' + buttonid + ','+roleid+')" href="javascript:;" title="授权"><i class="Hui-iconfont">&#xe615;</i></a>';
    }
    return html;
}
</script>
</body>
</html>